﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class BasicBase_Listenner_CadreList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            Bind();
            Bind3();
            
        }
    }

    private void Bind()
    {
        string Dept = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Dept == null || Dept.Length < 5)
            return;

        string strSql = "";
        if (Dept.Substring(0, 4).Equals("1300"))
            strSql += " 1=1";
        else
            strSql += " Left(DepartmentID,4)='" + Dept.Substring(0, 4) + "'";

        this.DptDepartment.DataSource = Yipusoft.Account.BLL.Department.GetList(strSql);
        this.DptDepartment.DataTextField = "FullName";
        this.DptDepartment.DataValueField = "DepartmentID";
        this.DptDepartment.DataBind();

        if (Dept.Substring(0, 4).Equals("1300"))
            DptDepartment.Items.Insert(0, new ListItem("(全部)单位", "00"));


        BtnSearch_Click(this.BtnSearch, new EventArgs());
    }

    protected void GvwList_RowDataBoundCadre(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblID = e.Row.FindControl("lblID") as Label;
            lblID.Text = Convert.ToString(GvwListCadre.PageSize * ListPageContral2.CurrentPageIndex + (e.Row.RowIndex + 1));
            //当鼠标放上去的时候 先保存当前行的背景颜色 并给附一颜色 
            e.Row.Attributes.Add("onmouseover", "currentcolor=this.style.backgroundColor;this.style.backgroundColor='#F5F5F5',this.style.fontWeight='';");
            //当鼠标离开的时候 将背景颜色还原的以前的颜色 
            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=currentcolor,this.style.fontWeight='';");
        }
    }
    protected void ListPageContral2_PageSizeChange(int pageSize, int PageIndex)
    {
        this.GvwListCadre.PageIndex = PageIndex;
        Bind3();
    }
    protected void Bind3()
    {
        string Dept = Yipusoft.Account.BLL.User.GetUser(User.Identity.Name).DepartmentID;
        if (Dept == null || Dept.Length < 5)
            return;

        string strSql = string.Empty;
        if (txtName.Text.Trim() != "")
            strSql = " UserName Like'%" + txtName.Text.Trim() + "%'";

        if (Dept.Substring(4, 1).Equals("0"))
        {
            if (strSql != string.Empty)
            {
                if (DptDepartment.SelectedValue.Equals("00"))
                {
                    strSql += " And 1=1";
                }
                else
                {
                    strSql += " And DepartmentID = '" + DptDepartment.SelectedValue + "'";
                }
            }
            else
            {
                if (DptDepartment.SelectedValue.Equals("00"))
                {
                    strSql = "  1=1 ";
                }
                else
                {
                    strSql = "  DepartmentID = '" + DptDepartment.SelectedValue + "'";
                }
            }
        }
        else
        {
            strSql = " DepartmentID = '" + DptDepartment.SelectedValue + "'" + " And " + strSql;
        }

        List<Yipusoft.Listener.Model.CallUser> list = Yipusoft.Listener.BLL.CallUser.GetList( " UserID in (Select UserID From DutyCadre Where " + strSql+")");
        if (list != null)
        {
            this.GvwListCadre.DataSource = list;
            this.ListPageContral2.ItemCount = list.Count();
            this.GvwListCadre.DataBind();
        }
    }
    protected void BtnSearch_Click(object sender, EventArgs e)
    {

        Bind3();
    }
    protected void Unnamed1_Command(object sender, CommandEventArgs e)
    {
        if (string.IsNullOrEmpty(e.CommandName))
            return;

        Yipusoft.Listener.BLL.CallUser.Delete(int.Parse(e.CommandName.Trim()));
        Bind3();
    }
}
